//
//  HMMainViewController.swift
//  Weibo
//
//  Created by 曾成 on 2017/6/4.
//  Copyright © 2017年 WickzZ. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let hmTabBar = HMTabBar()
        
        //设置点击撰写按钮执行的闭包
        hmTabBar.composeCallBack = {[weak self] in
        
            print("我是闭包传过来的")
            print(self)
        }
        
        //使用kvc可以给oc里的只读属性赋值,可以给私有成员变量赋值
        self.setValue(hmTabBar, forKey: "tabBar")
       // addChildViewController(childViewController:UIViewController)
        
        addChildViewController(childController: HMHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(childController: DiscoveryTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: HMMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: HMMeTableViewController(), title: "我的", imageName: "tabbar_profile")
        
        
    }
    
    //重载添加子视图控制器的方法
    func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        
        //设置tabBar属性
        childController.tabBarItem.image = UIImage(named:imageName)
        childController.tabBarItem.selectedImage = UIImage(named:"\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        
        //设置文字属性
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
        //设置文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize:13)], for: .normal)
        
        childController.title = title
        
        let nav = HMNavigationController(rootViewController: childController)
        
        //添加子视图
        addChildViewController(nav)
    }
}
